package com.xbongbong.saas.domain.entity;/*/*/

import com.xbongbong.paas.toolbox.util.StringUtil;
import com.xbongbong.paas.toolbox.wrap.Entity;
import com.xbongbong.pro.constant.I18nStringConstant;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.context.i18n.LocaleContextHolder;

import java.util.Locale;
import java.util.Objects;

/**
 * 工单模板entity
 * @author 魏荣杰
 * @date 2019/3/5 11:19
 * @since v1.0
 * @version v1.0
 */
@Setter
@Getter
@ToString
public class WorkOrderTemplateEntity extends Entity{
    private static final long serialVersionUID = 5501318522958802104L;
    /**
     * 主键id
     */
    private Long id;
    /**
     * 公司id
     */
    private String corpid;
    /**
     * 应用id
     */
    private Long appId;
    /**
     * 关联模板分类id
     */
    private Long categoryId;
    /**
     * 模板名称
     */
    private String name;
    /**
     * 模板名称英文版
     */
    private String nameEn;
    /**
     * 模板简介
     */
    private String introduction;
    /**
     * 是否为自由指派 1是，0不是
     */
    private Integer isFree;
    /**
     * 抄送人
     */
    private String cc;
    /**
     * 是否开启 1开启，0关闭
     */
    private Integer enable;
    /**
     * 是否为默认，1为默认分类，0不是默认分类
     */
    private Integer isDefault;
    /**
     * 模板分配权限规则（部门，人员）
     */
    private String scopeRule;
    /**
     * 创建人ID
     */
    private String creatorId;
    /**
     * 创建人姓名
     */
    private String creatorName;
    /**
     * 最近修改人id
     */
    private String modifierId;
    /**
     * 最近修改人的姓名
     */
    private String modifierName;
    /**
     * 添加时间
     */
    private Long addTime;
    /**
     * 更新时间
     */
    private Long updateTime;
    /**
     * 删除标记
     */
    private Integer del;
    /**
     * 预计耗时
     */
    private Integer expectedTime;
    /**
     * 镜像工单模板id(镜像应用复制时使用)
     */
    private Long mirrorTemplateId;

    public WorkOrderTemplateEntity() {
    }

    public WorkOrderTemplateEntity(String corpid, Long appId, Long categoryId, String name, String introduction, Integer isFree, String cc, Integer enable, Integer isDefault, String scopeRule, String creatorId, String creatorName, String modifierId, String modifierName, Long addTime, Long updateTime, Integer del, Integer expectedTime) {
        this.corpid = corpid;
        this.appId = appId;
        this.categoryId = categoryId;
        this.name = name;
        this.introduction = introduction;
        this.isFree = isFree;
        this.cc = cc;
        this.enable = enable;
        this.isDefault = isDefault;
        this.scopeRule = scopeRule;
        this.creatorId = creatorId;
        this.creatorName = creatorName;
        this.modifierId = modifierId;
        this.modifierName = modifierName;
        this.addTime = addTime;
        this.updateTime = updateTime;
        this.del = del;
        this.expectedTime = expectedTime;
    }

    public String getName() {
        Locale locale = LocaleContextHolder.getLocale();
        if (Objects.equals(locale.getLanguage(), I18nStringConstant.ENGLISH_LANGUAGE)&& StringUtil.isNotEmpty(nameEn)) {
            return nameEn;
        }
        return name;
    }

    public String getNameEn() {
        Locale locale = LocaleContextHolder.getLocale();
        if (Objects.equals(locale.getLanguage(), I18nStringConstant.ENGLISH_LANGUAGE)) {
            return name;
        }
        return nameEn;
    }
}
